package util.manager;

import java.util.Calendar;
import java.util.Date;

public class DateManager {
	private static Calendar getCalendarByDate(Date date){
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}
	
	/**
	 * Date 객체에서 년도 값 반환
	 * @param date
	 * @return
	 */
	public static int getYear(Date date){
		return getCalendarByDate(date).get(Calendar.YEAR);
	}
	
	/**
	 * Date 객체에서 월 값 반환
	 * @param date
	 * @return
	 */
	public static int getMonth(Date date){
		return getCalendarByDate(date).get(Calendar.MONTH)+1;
	}
	
	/**
	 * Date 객체에서 일 값 반환
	 * @param date
	 * @return
	 */
	public static int getDate(Date date){
		return getCalendarByDate(date).get(Calendar.DATE);
	}
	
	/**
	 * 오늘 날짜의 Date 객체인지 비교
	 * @param date
	 * @return
	 */
	public static boolean isToday(Date date){
		Date today=new Date();
		return (getYear(date)==getYear(today) 
				&& getMonth(date)==getMonth(today) 
				&& getDate(date)==getDate(today));
	}
	
	/**
	 * 년,월,일로 Date객체 반환. Date에 있는 생성자가 depreciate.
	 * @param year 년도전체 입력(ex 2015)
	 * @param month
	 * @param date
	 * @return
	 */
	public static Date getDateObject(int year, int month, int date){
		Calendar calendar=Calendar.getInstance();
		calendar.set(year, month-1, date);
		return calendar.getTime();
	}
}
